<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8" %>
<!DOCTYPE HTML>
<html>

<head>

</head>
<body>
<style>
    form div {
        white-space: nowrap;
    }
</style>
<div class="pd-10">
    <div class="text-c">
        <input type="text"  placeholder=" 角色名" style="width:120px" class="input-text"id="username">&nbsp;&nbsp;&nbsp;
        <button  id="doSearch" onclick="doSearch()" class="btn btn-success radius" ><i class="Hui-iconfont">&#xe665;</i> 搜角色
        </button>
    </div>
    <div style="margin-top: 5px">
        <table id="searchTable" >
            <tr>
                <th w_num="line" width="5%;"></th>
                <%--<th w_check="true" w_index="unid" width="5%;"></th>--%>
                <th w_index="rolename" w_sort="rolename"width="20%;">角色名称</th>
                <th w_index="createdate"w_sort="createdate"  width="20%">创建时间</th>
                <th w_index="enable" w_render="roleStatus" w_sort="enable"  width="20%" >状态</th>
                <th w_render="operate" width="10%;">操作</th>
            </tr>
        </table>
    </div>
</div>
</body>
</html>
<%@include file="../../head-ui.jsp" %>

<script type="text/javascript">

    function role_use(unid,flag){
        layer.confirm('确认操作吗？',function(){
            $.post( $("#contextPath").val()+"/back/user/dorolelink.do", {roleunid:unid,enable:flag,userunid:'${user.unid}'}, function(res){
                if(res.success==true){
                    doSearch();
                    layer.msg('成功!',{icon: 1,time:1000});
                }else{
                    layer.msg('失败!',{icon: 1,time:1000});
                }

            })
        });
    }
    function doSearch() {
        var searchParames = { username: encodeURI($("#username").val())};
        gridObj.search(searchParames);
    }
    function operate(record, rowIndex, colIndex, options) {
        if(record.enable=='1') {
            return "<a title='停用' href='javascript:void(0)' " +
                    "onClick=\"role_use('" + record.unid + "',0)\" class='ml-5' style='text-decoration:none'><i class='Hui-iconfont'>&#xe631;</i></a>";
        }else{
            return "<a title='启用' href='javascript:void(0)' " +
                    "onClick=\"role_use('" + record.unid + "',1)\" class='ml-5' style='text-decoration:none'><i class='Hui-iconfont'>&#xe615;</i></a>";
        }
    }
    function roleStatus(record, rowIndex, colIndex, options) {
        return record.enable == '1' ? "<span class='label label-success radius'>已启用</span>" : "<span class='label radius'>未启用</span>";
    }
    $(function () {
        gridObj = $.fn.bsgrid.init('searchTable', {
            url: '<%=request.getContextPath()%>/back/user/allRolesByuser.do?userunid=${user.unid}',
            // autoLoad: false,
            pageSizeSelect: true,
            pagingLittleToolbar: true,
            stripeRows: true,
            pageSize: 20,
            rowHoverColor: true,
            stripeRows: true,
            displayBlankRows: false
        });
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });
    })

</script>
